home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Tele / M / MFNotify.cpt / MFNotify.c next >
C/C++ Source or Header  |  1989-11-09  |  5KB  |  260 lines

  1. #include "MacTypes.h"
  2. #include "QuickDraw.h"
  3. #include "DeviceMgr.h"
  4. #include "EventMgr.h"
  5. #include "FileMgr.h"
  6. #include "MemoryMgr.h"
  7. #include "ResourceMgr.h"
  8. #include "WindowMgr.h"
  9. #include "SetUpA4.h"
  10.  
  11. typedef struct
  12.     {
  13.     long    thenum[234];
  14.     } NumVar,*NumVarPtr;
  15.  
  16. typedef struct
  17.     {
  18.     Byte    thestr[234][134];
  19.     } Strings,*StrVarPtr;
  20.  
  21. typedef struct
  22.     {
  23.     Byte    theparam[8350];
  24.     } RedParam,*RedPtr;
  25.  
  26. typedef struct
  27.     {
  28.     Byte    theval[20];
  29.     } Byte20,*Byte20Ptr;
  30.  
  31. typedef struct
  32.     {
  33.     Byte    data[1024];
  34.     } Buff1K,*Ptr1K;
  35.  
  36. typedef struct
  37.     {
  38.     Byte    data[2048];
  39.     } Buff2K,*Ptr2K;
  40.  
  41. typedef struct
  42.     {
  43.     Byte    thechar[256][2];
  44.     } Filter,*FilterPtr;
  45.  
  46. typedef struct
  47.     {
  48.     Byte    YesNoFlag;
  49.     Byte    ErrorFlag;
  50.     } FlagRec,*FlagPtr;
  51.  
  52. typedef struct
  53.     {
  54.     Byte    thepath[123];
  55.     } Byte123,*Ptr123;
  56.  
  57. typedef struct
  58.     {
  59.     unsigned short    red;
  60.     unsigned short    green;
  61.     unsigned short    blue;
  62. } RGBColor;
  63.  
  64. typedef struct
  65.     {
  66.     NumVarPtr    Numeric;
  67.     StrVarPtr    String;
  68.     RedPtr        RedParams;
  69.     Ptr            Reserved1;
  70.     long        Reserved2;
  71.     long        Reserved3;
  72.     long        Reserved4;
  73.     short        Reserved5;
  74.     ParmBlkPtr    UserBlock1;
  75.     ParmBlkPtr    UserBlock2;
  76.     ParmBlkPtr    SerialIn;
  77.     ParmBlkPtr    SerialOut;
  78.     Byte20Ptr    RadioGroup;
  79.     Byte20Ptr    CheckBox;
  80.     Ptr1K        Buffer1K;
  81.     Ptr2K        Buffer2K;
  82.     FilterPtr    TFilter;
  83.     FilterPtr    FFilter;
  84.     FilterPtr    PFilter;
  85.     FlagPtr        Flags;
  86.     Ptr123        RecPath;
  87.     RGBColor    Forecolor;
  88.     RGBColor    Backcolor;
  89.     RGBColor    Hilcolor;
  90.     RGBColor    SBfore;
  91.     RGBColor    SBback;
  92.     RGBColor    SBhil;
  93.     RGBColor    Phonefore;
  94.     RGBColor    Phoneback;
  95.     RGBColor    Phonehil;
  96.     RGBColor    Indfore;
  97.     RGBColor    Indback;
  98.     RGBColor    Rlefore;
  99.     RGBColor    Rleback;
  100.     WindowPeek    RedsWindow;
  101.     short        DoUpdate;
  102.     Rect        TransferRect;
  103.     short        Version;
  104.     } RParam,*RPtr;
  105.  
  106.  
  107. /* Globals used in this RCMD */
  108.  
  109. NMRec *therec;
  110. EventRecord event;
  111. ParamBlockRec volblock;
  112. WindowPtr whichWin;
  113. Handle thesnd;
  114. unsigned long sresize;
  115. Handle thesicn;
  116. short idnum;
  117.  
  118. /*
  119. Install MultiFinder Notification Manager alert.
  120. Changes value of S%,I%, and A%
  121. Text for dialog box is in T$.
  122. S% = 0, use no sound
  123. S% < 0, use BeepSound
  124. S% > 0, play 'snd ' resource ID number S%.
  125. For debugging purposes:
  126. if (S% > 0) S% returns 0 if no error, 1 if not enough free memory to hold
  127.     'snd ' resource, or 2 if 'snd ' resource not found.
  128. I% = 0, use no small icon in Apple menu
  129. I% < 0, use White Knight small icon in Apple menu
  130. I% > 0, use 'SICN' resource ID number I%.
  131. For debugging purposes:
  132. if (I% > 0) I% returns 0 if no error, 1 if not enough free memory to hold
  133.     'SICN' resource, or 2 if 'SICN' resource not found.
  134. A% holds the result code of the MultiFinder Notification Manager install attempt.
  135. */
  136.  
  137.  
  138.  
  139. pascal void ResponseProc();
  140.  
  141. /* Start of code resource */
  142. pascal void main(params)
  143. RPtr params;
  144. {
  145. RememberA0();
  146. SetUpA4();
  147. thesnd = thesicn = 0L;
  148. therec = (NMRec *)NewPtr(sizeof(NMRec));
  149. therec->nmMark = 1;
  150. therec->nmStr = params->String->thestr[19];
  151. therec->nmResp = ResponseProc;
  152. therec->qType = 8;
  153. therec->nmRefCon = 1;
  154. if (params->Numeric->thenum[8] == 0) therec->nmSIcon = 0L;
  155. else
  156.     {
  157.     if (params->Numeric->thenum[8] < 0) idnum = 8000; else idnum = (int)params->Numeric->thenum[8];
  158.     SetResLoad(0);
  159.     thesicn = (Handle)GetResource((long)'SICN',idnum);
  160.     if (ResError())
  161.         {
  162.         therec->nmSIcon = 0L;
  163.         params->Numeric->thenum[8] = 2;
  164.         goto CONTINUE;
  165.         }
  166.     sresize = SizeResource(thesicn);
  167.     SetResLoad(1);
  168.     ResrvMem(sresize);
  169.     if (MemError() != 0)
  170.         {
  171.         therec->nmSIcon = 0L;
  172.         params->Numeric->thenum[8] = 1;
  173.         goto CONTINUE;
  174.         }    
  175.     LoadResource(thesicn);
  176.     HLock(thesicn);
  177.     params->Numeric->thenum[8] = 0;
  178.     therec->nmSIcon = thesicn;
  179.     }
  180. CONTINUE:
  181. if (params->Numeric->thenum[18] == -1L) therec->nmSound = (Handle)-1L;
  182. if (params->Numeric->thenum[18] == 0L) therec->nmSound = 0L;
  183. if (params->Numeric->thenum[18] > 0)
  184.     {
  185.     SetResLoad(0);
  186.     thesnd = (Handle)GetResource((long)'snd ',(int)params->Numeric->thenum[18]);
  187.     if (ResError())
  188.         {
  189.         therec->nmSound = (Handle)-1L;
  190.         params->Numeric->thenum[18] = 2;
  191.         goto CONT2;
  192.         }
  193.     sresize = SizeResource(thesnd);
  194.     SetResLoad(1);
  195.     ResrvMem(sresize);
  196.     if (MemError() != 0)
  197.         {
  198.         therec->nmSound = (Handle)-1L;
  199.         params->Numeric->thenum[18] = 1;
  200.         goto CONT2;
  201.         }    
  202.     LoadResource(thesnd);
  203.     HLock(thesnd);
  204.     params->Numeric->thenum[18] = 0;
  205.     therec->nmSound = thesnd;
  206.     }
  207. CONT2:
  208. if (params->Numeric->thenum[0] = NMInstall(therec))
  209.     {
  210.     SysBeep(60);
  211.     goto EXIT;
  212.     }
  213. while (therec->nmRefCon) DoEvent();
  214. NMRemove(therec);
  215. EXIT:
  216. if (thesnd)
  217.     {
  218.     HUnlock(thesnd);
  219.     DisposHandle(thesnd);
  220.     }
  221. if (thesicn)
  222.     {
  223.     HUnlock(thesicn);
  224.     DisposHandle(thesicn);
  225.     }
  226. DisposPtr(therec);
  227. RestoreA4();
  228. }
  229.  
  230.  
  231. pascal void ResponseProc(nmReqPtr)
  232. NMRec *nmReqPtr;
  233. {
  234. nmReqPtr->nmRefCon = 0;
  235. }
  236.  
  237. DoEvent()
  238. {
  239. integer wheremouse,OSerr;
  240. SystemTask();
  241. if (!GetNextEvent(-1,&event)) return;
  242. switch (event.what)
  243.     {
  244.     case diskEvt:
  245.             volblock.ioParam.ioVRefNum = (short)(event.message);
  246.             OSerr = PBMountVol(&volblock);
  247.         break;
  248.     case mouseDown:
  249.         wheremouse = FindWindow(event.where,&whichWin);
  250.         switch (wheremouse)
  251.             {
  252.             case inSysWindow:
  253.                                    SystemClick(&event,whichWin);  /* system event */
  254.                                    break;
  255.             }
  256.         break;
  257.     }
  258. }            
  259.  
  260.